Ext.define('Admin.view.user.manager.UserManagerGrid', {
    extend: 'Ext.grid.Panel',
    xtype: 'userManagerGrid',
    id: 'userManagerGrid',

    title: '用户管理',
    iconCls: 'x-fa fa-edit',

    controller: 'userManagerViewController',

    viewModel: {
        type: 'userManagerViewModel'
    },

    bind: '{userList}',

    selModel: Ext.create('Ext.selection.CheckboxModel'),

    columns: [{
            header: 'id',
            dataIndex: 'id',
            width: 80,
            sortable: true,
            hidden: true
        }, {
            header: '头像',
            dataIndex: 'cover',
            width: 100,
            renderer: function(value) {
                return "<img height='50' width='50' alt='' src='upload/"+value+"'></img>"
            }
        },{
            header: '姓名',
            dataIndex: 'fullname',
            width: 120,
            flex: 1,
            sortable: true
        },
        {
            header: '年龄',
            dataIndex: 'age',
            width: 50,
            sortable: true
        },
        {
            header: '性别',
            dataIndex: 'sex',
            width: 50,
            sortable: true,
            renderer: function(value) {
                if (value == 'male') {
                    return '男';
                } else if (value == 'female') {
                    return '女';
                } else {
                    return '';
                }
            }
        },
        {
            header: '联系电话',
            dataIndex: 'phone',
            width: 120,
            flex: 1,
            sortable: true,

        },
        {
            header: '电子邮箱',
            dataIndex: 'email',
            width: 160,
            flex: 1,
            sortable: true,
        },
        {
            header: '部门',
            dataIndex: 'dept',
            width: 70,
            sortable: true
        },
        {
            header: '职位',
            dataIndex: 'job',
            width: 100,
            sortable: true
        },
        {
            header: '入职日期',
            dataIndex: 'enterTime',
            width: 120,
            sortable: true,
            renderer: Ext.util.Format.dateRenderer('Y/m/d')
        }, {
            header: '操作',
            xtype: 'actioncolumn',
            cls: 'content-column',
            width: 100,
            flex: 1,
            text: '操作',
            items: [{
                xtype: 'button',
                iconCls: 'x-fa fa-eye',
                tooltip: '查看',
                handler: 'onClickUserManagerWatchButton'
            }, {
                xtype: 'button',
                iconCls: 'x-fa fa-edit',
                tooltip: '编辑',
                handler: 'onClickUserManagerEditButton'
            }, {
                xtype: 'button',
                iconCls: 'x-fa fa-trash-o',
                tooltip: '删除',
                handler: 'onClickUserManagerDeleteButton'
            }]
        }
    ],

    tbar: Ext.create('Ext.toolbar.Toolbar', {
        items: [{
            xtype: 'combobox',
            reference: 'queryBox',
            queryMode: 'local',
            displayField: 'key',
            valueField: 'value',
            emptyText: '请选择...',
            editable: false,
            store: Ext.create('Ext.data.Store', {
                fields: ['key', 'value'],
                data: [
                    { "key": '姓名', "value": 'fullname' },
                    { "key": '部门', "value": 'dept' },
                    { "key": '职位', "value": 'job' }
                ]
            })
        }, {
            xtype: 'textfield',
            reference: 'searchQuery',
            emptyText: '关键字'
        }, {
            text: '重置',
            listeners: {
                click: 'onClickUserGridResetButton'
            }
        }, {
            text: '提交',
            listeners: {
                click: 'onClickUserGridSearchButton'
            }
        }]
    }),

    bbar: Ext.create('Ext.PagingToolbar', {
        bind: '{userList}',
        displayInfo: true,
        displayMsg: '显示第 {0} - {1} 条数据 总计 {2}',
        emptyMsg: "没有任何数据",
        items: ['-', {
            text: '删除',
            iconCls: 'x-fa fa-trash-o',
            listeners: {
                click: 'onClickUserManagerDeleteUsersButton'
            }
        }]
    })
});